package main

import (
	"fmt"
	"time"
)

const MAX = 41

var fibs [MAX]uint64

func main() {
	var result uint64 = 0
	start := time.Now()
	for i := 0; i < MAX; i++ {
		result = fibonacci(i)
		fmt.Printf("fibonacci(%d) is: %d \n", i, result)
	}
	end := time.Now()
	delta := end.Sub(start)
	fmt.Printf("longCalculation took this amount of time: %s \n ", delta)
	start2 := time.Now()
	fibonacci(40)
	delta2 := time.Now().Sub(start2)
	fmt.Printf("longCalculation took this amount of time2: %s \n ", delta2)
}

func fibonacci(n int) (res uint64) {
	if fibs[n] != 0 {
		res = fibs[n]
		return
	}
	if n <= 1 {
		res = 1
	} else {
		res = fibonacci(n-1) + fibonacci(n-2)
	}
	fibs[n] = res
	return
}
